﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MyTest
{
    /// <summary>
    /// 教员:薛海
    /// 微信:xuehai03
    /// QQ:289477003
    /// 猜数小游戏
    /// 2019-2-20
    /// </summary>
    public partial class frmCai : Form
    {
        public frmCai()
        {
            InitializeComponent();
        }
        //数字
        int num = 0;
        //次数
        int count = 0;

        //新游戏
        private void btnNew_Click(object sender, EventArgs e)
        {
            Random r = new Random();
            this.num = r.Next(1, 100);
            this.count = 0;
            this.btnCai.Enabled = true;
            this.txtNum.Text = string.Empty;
        }

        //开始游戏
        private void btnCai_Click(object sender, EventArgs e)
        {
            if (this.txtNum.Text.Trim().Equals(string.Empty))
            {
                MessageBox.Show("请输入数字", "提示");
            }
            else { 
                if(Convert.ToInt32(this.txtNum.Text.Trim())>this.num)
                {
                    MessageBox.Show("大了,再猜");
                    count++;
                }
                if(Convert.ToInt32(this.txtNum.Text.Trim())<this.num)
                {
                    MessageBox.Show("小了,再猜");
                    count++;
                }
                if(Convert.ToInt32(this.txtNum.Text.Trim())==this.num)
                {
                    this.count++;
                    string msg = "恭喜你,猜中了,共猜"+count+"次";
                    MessageBox.Show(msg,"提示");
                    this.btnCai.Enabled = false;
                }
            }
        }
    }
}
